package com.youlu.campus.admin.community.controller;

import com.youlu.campus.admin.community.dto.*;
import com.youlu.campus.admin.community.service.TopicService;
import com.youlu.campus.base.base.GeneraStatusEnum;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 话题管理控制层
 * @author: YangJ
 * @date: 2020/11/24 18:05
 */
@RestController
public class TopicController {

    @Autowired
    private TopicService topicService;

    /**
     * 创建话题
     * @param request 话题信息创建请求类
     * @return
     */
    @PostMapping("/topic/create")
    public QResult createTopic(@RequestBody TopicCreateRequest request){
        boolean result = topicService.createTopic(request);
        return QResult.success(result);
    }

    /**
     * 修改话题
     * @param request 话题信息修改请求类
     * @return
     */
    @PostMapping("/topic/update")
    public QResult updateTopic(@RequestBody TopicUpdateRequest request){
        boolean result = topicService.updateTopic(request);
        return QResult.success(result);
    }

    /**
     * 上架
     * @param id 话题ID
     * @return
     */
    @PostMapping("/topic/on")
    public QResult onTopic(String id){
        boolean result = topicService.updateTopicStatus(id, GeneraStatusEnum.ON.getCode());
        return QResult.success(result);
    }

    /**
     * 下架
     * @param id 话题ID
     * @return
     */
    @PostMapping("/topic/off")
    public QResult offTopic(String id){
        boolean result = topicService.updateTopicStatus(id,GeneraStatusEnum.OFF.getCode());
        return QResult.success(result);
    }

    /**
     * 修改话题权重
     * @param request 话题权重信息请求类
     * @return
     */
    @PostMapping("/topic/update/weight")
    public QResult updateWeight(@RequestBody WeightRequest request){
        boolean result = topicService.updateWeight(request);
        return QResult.success(result);
    }

    /**
     * 删除话题
     * @param id 话题ID
     * @return
     */
    @DeleteMapping("/topic/delete")
    public QResult deleteTopic(String id){
        boolean result = topicService.deleteTopic(id);
        return QResult.success(result);
    }

    /**
     * 话题列表
     * @param request 话题信息查询请求类
     * @return
     */
    @PostMapping("/topic/list")
    public QResult topicRoomList(@RequestBody TopicQueryRequest request){
        return QResult.success(topicService.topicList(request));
    }

    /**
     * 话题信息查询
     * @param id 话题ID
     * @return
     */
    @GetMapping("/topic/query")
    public QResult topicRoomList(String id){
        return QResult.success(topicService.query(id));
    }
}
